package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysMchConfigMapper;
import com.ruoyi.system.domain.SysMchConfig;
import com.ruoyi.system.service.ISysMchConfigService;

import cn.hutool.core.collection.CollUtil;

/**
 * 商户配置Service业务层处理
 * 
 * @author zhoudong
 * @date 2024-03-22
 */
@Service
public class SysMchConfigServiceImpl implements ISysMchConfigService 
{
    @Autowired
    private SysMchConfigMapper sysMchConfigMapper;

    /**
     * 查询商户配置
     * 
     * @param id 商户配置主键
     * @return 商户配置
     */
    @Override
    public SysMchConfig selectSysMchConfigById(Long id)
    {
        return sysMchConfigMapper.selectSysMchConfigById(id);
    }

    /**
     * 查询商户配置列表
     * 
     * @param sysMchConfig 商户配置
     * @return 商户配置
     */
    @Override
    public List<SysMchConfig> selectSysMchConfigList(SysMchConfig sysMchConfig)
    {
        return sysMchConfigMapper.selectSysMchConfigList(sysMchConfig);
    }

    /**
     * 新增商户配置
     * 
     * @param sysMchConfig 商户配置
     * @return 结果
     */
    @Override
    public int insertSysMchConfig(SysMchConfig sysMchConfig)
    {
        sysMchConfig.setCreateTime(DateUtils.getNowDate());
        return sysMchConfigMapper.insertSysMchConfig(sysMchConfig);
    }

    /**
     * 修改商户配置
     * 
     * @param sysMchConfig 商户配置
     * @return 结果
     */
    @Override
    public int updateSysMchConfig(SysMchConfig sysMchConfig)
    {
        sysMchConfig.setUpdateTime(DateUtils.getNowDate());
        return sysMchConfigMapper.updateSysMchConfig(sysMchConfig);
    }

    /**
     * 批量删除商户配置
     * 
     * @param ids 需要删除的商户配置主键
     * @return 结果
     */
    @Override
    public int deleteSysMchConfigByIds(Long[] ids)
    {
        return sysMchConfigMapper.deleteSysMchConfigByIds(ids);
    }

    /**
     * 删除商户配置信息
     * 
     * @param id 商户配置主键
     * @return 结果
     */
    @Override
    public int deleteSysMchConfigById(Long id)
    {
        return sysMchConfigMapper.deleteSysMchConfigById(id);
    }

    /**
     * 根据商户ID获取配置
     * @param mchId
     */
    @Override
    public SysMchConfig selectByMchId(Long mchId) {
        SysMchConfig query = new SysMchConfig();
        query.setMchId(mchId);

        List<SysMchConfig> mchConfigs = sysMchConfigMapper.selectSysMchConfigList(query);
        if (CollUtil.isNotEmpty(mchConfigs)) {
            return mchConfigs.get(0);
        }
        return null;
    }
}
